home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0192.ARJ / MODE.ASM < prev    next >
Assembly Source File  |  1991-04-01  |  3KB  |  85 lines

  1. ; Mode X (320x240, 256 colors) mode set routine. Works on all VGAs.
  2. ; C near-callable as:
  3. ;       void Set320x240Mode(void);
  4. ; Tested with TASM 2.0.
  5. ; Modified from public-domain mode set code by John Bridges.
  6.  
  7. SC_INDEX equ    03c4h   ;Sequence Controller Index
  8. CRTC_INDEX equ  03d4h   ;CRT Controller Index
  9. MISC_OUTPUT equ 03c2h   ;Miscellaneous Output register
  10. SCREEN_SEG equ  0a000h  ;segment of display memory in mode X
  11.  
  12.         .model  small
  13.         .data
  14. ; Index/data pairs for CRT Controller registers that differ between
  15. ; mode 13h and mode X.
  16. CRTParms label  word
  17.         dw      00d06h  ;vertical total
  18.         dw      03e07h  ;overflow (bit 8 of vertical counts)
  19.         dw      04109h  ;cell height (2 to double-scan)
  20.         dw      0ea10h  ;v sync start
  21.         dw      0ac11h  ;v sync end and protect cr0-cr7
  22.         dw      0df12h  ;vertical displayed
  23.         dw      00014h  ;turn off dword mode
  24.         dw      0e715h  ;v blank start
  25.         dw      00616h  ;v blank end
  26.         dw      0e317h  ;turn on byte mode
  27. CRT_PARM_LENGTH equ     (($-CRTParms)/2)
  28.  
  29.         .code
  30.         public  _Set320x240Mode
  31. _Set320x240Mode proc    near
  32.         push    bp      ;preserve caller's stack frame
  33.         push    si      ;preserve C register vars
  34.         push    di      ; (don't count on BIOS preserving anything)
  35.  
  36.         mov     ax,13h  ;let the BIOS set standard 256-color
  37.         int     10h     ; mode (320x200 linear)
  38.  
  39.         mov     dx,SC_INDEX
  40.         mov     ax,0604h
  41.         out     dx,ax   ;disable chain4 mode
  42.         mov     ax,0100h
  43.         out     dx,ax   ;synchronous reset while switching clocks
  44.  
  45.         mov     dx,MISC_OUTPUT
  46.         mov     al,0e7h
  47.         out     dx,al   ;select 28 MHz dot clock & 60 Hz scanning rate
  48.  
  49.         mov     dx,SC_INDEX
  50.         mov     ax,0300h
  51.         out     dx,ax   ;undo reset (restart sequencer)
  52.  
  53.         mov     dx,CRTC_INDEX ;reprogram the CRT Controller
  54.         mov     al,11h  ;VSync End reg contains register write
  55.         out     dx,al   ; protect bit
  56.         inc     dx      ;CRT Controller Data register
  57.         in      al,dx   ;get current VSync End register setting
  58.         and     al,7fh  ;remove write protect on various
  59.         out     dx,al   ; CRTC registers
  60.         dec     dx      ;CRT Controller Index
  61.         cld
  62.         mov     si,offset CRTParms ;point to CRT parameter table
  63.         mov     cx,CRT_PARM_LENGTH ;# of table entries
  64. SetCRTParmsLoop:
  65.         lodsw           ;get the next CRT Index/Data pair
  66.         out     dx,ax   ;set the next CRT Index/Data pair
  67.         loop    SetCRTParmsLoop
  68.  
  69.         mov     dx,SC_INDEX
  70.         mov     ax,0f02h
  71.         out     dx,ax   ;enable writes to all four planes
  72.         mov     ax,SCREEN_SEG ;now clear all display memory, 8 pixels
  73.         mov     es,ax         ; at a time
  74.         sub     di,di   ;point ES:DI to display memory
  75.         sub     ax,ax   ;clear to zero-value pixels
  76.         mov     cx,8000h ;# of words in display memory
  77.         rep     stosw   ;clear all of display memory
  78.  
  79.         pop     di      ;restore C register vars
  80.         pop     si
  81.         pop     bp      ;restore caller's stack frame
  82.         ret
  83. _Set320x240Mode endp
  84.         end
  85.